<html>
<head><meta charset="utf-8"><title>rustdoc is using rustc_ast_pretty, would … compiler-team#403 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html">rustdoc is using rustc_ast_pretty, would … compiler-team#403</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224394018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224394018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224394018">(Jan 28 2021 at 21:18)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/403">rustdoc is using rustc_ast_pretty, would it be possible to make it somewhat "stable"? #403</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="224395162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224395162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224395162">(Jan 28 2021 at 21:28)</a>:</h4>
<p>What's meant by "stabilize" here? Why can't we update rustdoc when something changes, like we do for other compiler parts?</p>



<a name="224481595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481595">(Jan 29 2021 at 14:59)</a>:</h4>
<p>this will still happen, the idea is to make sure everyone is aware that touching the pretty printer can aversely affect rustdoc output.</p>



<a name="224481814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481814">(Jan 29 2021 at 15:00)</a>:</h4>
<p>I felt uneasy just using the "pretty" printer to generate user-visible text in rustdoc (and thus also adjusting pretty printing to be prettier in some cases so that users don't get weird documentation)</p>



<a name="224481841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481841">(Jan 29 2021 at 15:00)</a>:</h4>
<p>Would part of this stabilization involve writing some kind of pretty-print tests so that we can easily validate that part of the compiler isn't changed? Or easily track when it does change?</p>



<a name="224481876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481876">(Jan 29 2021 at 15:00)</a>:</h4>
<p>ideally rustdoc tests will catch it</p>



<a name="224481934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481934">(Jan 29 2021 at 15:01)</a>:</h4>
<p>if we start using pprint more extensively in rustdoc, that may not always be the case</p>



<a name="224481945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224481945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224481945">(Jan 29 2021 at 15:01)</a>:</h4>
<p>which is fine</p>



<a name="224482091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224482091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224482091">(Jan 29 2021 at 15:02)</a>:</h4>
<p>but I still think we should make a concious decision about using pprint in rustdoc and not just silently do that and suddenly start making changes to pprint that make no sense if looking at it just from the pprint perspective</p>



<a name="224482146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/224482146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#224482146">(Jan 29 2021 at 15:02)</a>:</h4>
<p>we previously turned down PRs making pprint prettier iirc</p>



<a name="225171836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225171836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225171836">(Feb 04 2021 at 15:11)</a>:</h4>
<p>How related is the pretty printer to rustfmt</p>



<a name="225171850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225171850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225171850">(Feb 04 2021 at 15:11)</a>:</h4>
<p>Doesn't rustfmt use the rust AST?</p>



<a name="225171876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225171876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225171876">(Feb 04 2021 at 15:11)</a>:</h4>
<p>I feel like ideally we'd have one unified thing that produces output visible to end users</p>



<a name="225172596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225172596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225172596">(Feb 04 2021 at 15:15)</a>:</h4>
<p>the pretty printer output is not at all readable AFAIR</p>



<a name="225521114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225521114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225521114">(Feb 08 2021 at 09:46)</a>:</h4>
<p>so what is rustdoc using the pretty printer <em>for</em>?</p>



<a name="225527395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225527395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225527395">(Feb 08 2021 at 10:54)</a>:</h4>
<p>I tried to read the code, to me it looks like it's using <code>pprust</code> to:</p>
<ul>
<li>print back the contents of <code>#![doc(test(..))]</code> to be injected in doctests</li>
<li>display certain attributes like <code>#[must_use]</code> in docs</li>
</ul>



<a name="225980440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/225980440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#225980440">(Feb 11 2021 at 12:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403/near/225521114">said</a>:</p>
<blockquote>
<p>so what is rustdoc using the pretty printer <em>for</em>?</p>
</blockquote>
<p>Currently, to display attributes</p>



<a name="243988525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/243988525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#243988525">(Jun 26 2021 at 01:52)</a>:</h4>
<p>and soon to display macros as well: <a href="https://github.com/rust-lang/rust/pull/86282">https://github.com/rust-lang/rust/pull/86282</a></p>



<a name="243988565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/243988565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#243988565">(Jun 26 2021 at 01:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403/near/225171876">said</a>:</p>
<blockquote>
<p>I feel like ideally we'd have one unified thing that produces output visible to end users</p>
</blockquote>
<p>I would <em>love</em> to use rustfmt. Now that rustfmt is in-tree that might actually be feasible. <span class="user-mention" data-user-id="320317">@Caleb Cartwright</span> would you be ok with rustdoc doing that?</p>



<a name="243988580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/243988580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#243988580">(Jun 26 2021 at 01:53)</a>:</h4>
<p>it shouldn't be a giant maintenance burden - you'd just have to fix rustdoc on submodule syncs (and it might end up making sense to change rustfmt in-tree so you can do both at once, but it's not required)</p>



<a name="244030741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244030741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244030741">(Jun 26 2021 at 19:36)</a>:</h4>
<p>It would add a pretty hefty dependency edge to rustdoc, though. I'm not sure, but if we're going to make it "the" pretty printer it's probably worth discussing replacing rustc's pp with rustfmt... but that's likely to bring lots of regressions due to close ties to proc macros</p>



<a name="244030839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244030839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244030839">(Jun 26 2021 at 19:38)</a>:</h4>
<p>I mean, I don't think you can have a larger dependency than "the rust compiler" haha, rustfmt is pretty small in comparison.</p>
<p>Is pretty-print used for proc-macros? That surprises me, I would expect them to be passed the AST directly</p>



<a name="244034177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244034177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244034177">(Jun 26 2021 at 21:00)</a>:</h4>
<p>They take token streams - we sometimes need to pretty print and retokenize</p>



<a name="244034205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244034205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244034205">(Jun 26 2021 at 21:01)</a>:</h4>
<p>well, in any case, I don't think rustc needs to use rustfmt for <code>--unpretty</code> in order for rustdoc to use it</p>



<a name="244047581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244047581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244047581">(Jun 27 2021 at 03:33)</a>:</h4>
<p>We no longer do this - some unstable positions for proc macros don't correctly capture token, but we've stopped re-tokenizimg streams that we do capture</p>



<a name="244066951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244066951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244066951">(Jun 27 2021 at 13:22)</a>:</h4>
<p>Ah, great</p>



<a name="244370823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244370823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244370823">(Jun 30 2021 at 02:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403/near/243988565">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403/near/225171876">said</a>:</p>
<blockquote>
<p>I feel like ideally we'd have one unified thing that produces output visible to end users</p>
</blockquote>
<p>I would <em>love</em> to use rustfmt. Now that rustfmt is in-tree that might actually be feasible. <span class="user-mention silent" data-user-id="320317">Caleb Cartwright</span> would you be ok with rustdoc doing that?</p>
</blockquote>
<p>sorry for the delayed response. have been playing with some email filters that did more harm than good apparently.</p>
<p>rustfmt's only supported input currently is either file paths or an input string, and regardless of which, the corresponding input needs to be parseable by rustc_parse because rustfmt works directly with the resulting AST. </p>
<p>i'm not sure what all would be in scope or how beneficial that type of interface would be to rustdoc. i'd guess not very, but if rustfmt can potentially be useful in other contexts i'm open to seeing where/how we can help</p>



<a name="244371822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244371822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244371822">(Jun 30 2021 at 02:44)</a>:</h4>
<p>Hmm, interesting. So rustc_ast_pretty probably needs to stick around for the original stringification and then rustdoc can pass it to rustfmt to make it nice and pretty.</p>
<p>Does rustfmt only format items? Or can it format smaller things, like patterns and expressions?</p>



<a name="244371848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244371848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244371848">(Jun 30 2021 at 02:45)</a>:</h4>
<p>(ideally rustfmt would take rustc_hir or rustc_ast types directly but if that's a pain, I don't think using ast_pretty <em>just</em> to get something parseable is a big deal)</p>



<a name="244372111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372111">(Jun 30 2021 at 02:50)</a>:</h4>
<p>Looks like rustfmt isn't currently documented on nightly-rustc, I'll see if that's easy to fix</p>



<a name="244372457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372457">(Jun 30 2021 at 02:58)</a>:</h4>
<blockquote>
<p>Does rustfmt only format items? Or can it format smaller things, like patterns and expressions?</p>
</blockquote>
<p>at the end of the day, it ultimately boils down to functions taking some AST node as input and producing a formatted string based on that input node. where it's tricky though is the public interface. we had asks from external cases (community consumption of the rustfmt lib)  to open up the public interface to support taking an AST as an input, which was something we weren't keen on for a variety of reasons. bit of a different story when talking about intra-rust libs/tools though, especially now that we're no longer consuming the ap crates within rustfmt</p>



<a name="244372550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372550">(Jun 30 2021 at 03:00)</a>:</h4>
<p>if it helps, I'm perfectly fine with any APIs being unstable and subject to change, as long as there's <em>a</em> replacement for any breakage</p>



<a name="244372885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372885">(Jun 30 2021 at 03:08)</a>:</h4>
<p>i'm definitely open to extending our api surface a bit to support some use cases. would be more concerned about figuring out a good "buyer beware" message to communicate to those consumers _outside_ the rust-lang org. think the first step towards looking at this would be an enumeration of the specific kinds of ast items you'd like to toss our way.</p>
<p>probably also worth noting that rustfmt support for macros is still extremely limited and often funky</p>



<a name="244372910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372910">(Jun 30 2021 at 03:09)</a>:</h4>
<p>heh, I was about to say I want to use rustfmt for macros <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="244372967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244372967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244372967">(Jun 30 2021 at 03:10)</a>:</h4>
<p>in particular <a href="https://github.com/rust-lang/rust/pull/86282">https://github.com/rust-lang/rust/pull/86282</a> is again hitting "rustc_ast_pretty is not intended for anything other than debugging"</p>



<a name="244373001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373001">(Jun 30 2021 at 03:11)</a>:</h4>
<p>in  general I would like to throw <em>lots</em> of things at rustfmt though, right now rustdoc basically rewrites half of it</p>



<a name="244373078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373078">(Jun 30 2021 at 03:12)</a>:</h4>
<p>(and that also lets me force rustdoc to stop using its own fork of the AST, which I really want to get rid of)</p>



<a name="244373180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373180">(Jun 30 2021 at 03:15)</a>:</h4>
<p>So I think a good incremental approach to this is:</p>
<ol start="0">
<li>Document rustfmt on rustc-nightly, since it's essentially free and gives me an idea of how rustfmt works (working on that now)</li>
<li>Change rustdoc to depend on rustfmt in-tree and pass some <em>very</em> basic things to it as a proof-of-concept. This can just be strings to start, I don't want to change rustfmt at this point.</li>
<li>If that goes well, start doing it for more things.</li>
<li>Look into formatting the AST directly instead of serializing and re-parsing. This is the only bit that would need changes to rustfmt I think, and rustdoc can still get a lot of benefit even without it.</li>
</ol>



<a name="244373266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373266">(Jun 30 2021 at 03:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403/near/244373001">said</a>:</p>
<blockquote>
<p>in  general I would like to throw <em>lots</em> of things at rustfmt though, right now rustdoc basically rewrites half of it</p>
</blockquote>
<p>that's where we'd likely want a bit of analysis. item, expr, stmt, type would probably be preferable to surface in terms of the api (from a rustfmt sourcecode POV) vs. every nitty gritty function for specific kinds</p>



<a name="244373346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373346">(Jun 30 2021 at 03:18)</a>:</h4>
<blockquote>
<p>So I think a good incremental approach to this is:</p>
</blockquote>
<p>sounds reasonable to me</p>



<a name="244373359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373359">(Jun 30 2021 at 03:19)</a>:</h4>
<p>Hmm, ok. Does that also apply to the current interface with strings? Does it only work for item/expr/stmt or can it deal with any fragment of rust code?</p>



<a name="244373563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373563">(Jun 30 2021 at 03:24)</a>:</h4>
<blockquote>
<p>Does it only work for item/expr/stmt or can it deal with any fragment of rust code?</p>
</blockquote>
<p>can't be a fragment, standalone stmt isn't formattable</p>



<a name="244373573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373573">(Jun 30 2021 at 03:24)</a>:</h4>
<p>that is unfortunate, ok</p>



<a name="244373765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244373765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Cartwright <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244373765">(Jun 30 2021 at 03:29)</a>:</h4>
<p>public interface and codeflow is very much geared towards that core check/rewrite files use case so i don't know how much you'd be able to squeeze out of the current state beyond items</p>
<p>rustfmt will use the new_parser_from_file or parser_from_source_string (forget exact names) functions and then calls parse_crate_mod, so any input string that won't pass that can't be used with rustfmt today</p>



<a name="244375402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244375402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244375402">(Jun 30 2021 at 04:07)</a>:</h4>
<p><span class="user-mention" data-user-id="320317">@Caleb Cartwright</span> uhhh does this error look familiar?</p>
<div class="codehilite"><pre><span></span><code> Documenting rustfmt-nightly v1.4.37 (/home/joshua/rustc/src/tools/rustfmt)
error[E0275]: overflow evaluating the requirement `std::ptr::Unique&lt;rustc_ast::Pat&gt;: std::marker::Send`
  |
  = help: consider adding a `#![recursion_limit=&quot;256&quot;]` attribute to your crate (`rustfmt_nightly`)
</code></pre></div>



<a name="244375463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/rustdoc%20is%20using%20rustc_ast_pretty%2C%20would%20%E2%80%A6%20compiler-team%23403/near/244375463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/rustdoc.20is.20using.20rustc_ast_pretty.2C.20would.20.E2.80.A6.20compiler-team.23403.html#244375463">(Jun 30 2021 at 04:08)</a>:</h4>
<p>well, increasing the limit does in fact work so I'll just do that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>